package org.apache.flink.runtime.resourceconsumer.runner;

import java.util.concurrent.CompletableFuture;

import org.apache.flink.api.common.ConsumerID;
import org.apache.flink.api.common.ResourceStatus;
import org.apache.flink.api.common.time.Time;
import org.apache.flink.runtime.allocation.ResourceAllocation;
import org.apache.flink.runtime.allocation.ResourceAllocationStatistics;
import org.apache.flink.runtime.cleanup.LocallyCleanableResource;
import org.apache.flink.runtime.messages.Acknowledge;
import org.apache.flink.runtime.resourceconsumer.ConsumeNotFinishedException;
import org.apache.flink.runtime.resourceconsumer.ResourceConsumer;
import org.apache.flink.runtime.resourceconsumer.ResourceConsumerGateway;
import org.apache.flink.util.AutoCloseableAsync;

/**
 * @类名: ResourceConsumerRunner
 * @说明: 资源消费者runner
 *
 * @author   leehom
 * @Date	 2023年10月26日 上午10:06:20
 * 修改记录：
 *
 * @see 	 
 */
public interface ResourceConsumerRunner extends AutoCloseableAsync, LocallyCleanableResource {

    /**
     * Start the execution of the {@link ResourceConsumer}.
     *
     * @throws Exception if the ResourceConsumer cannot be started
     */
    void start() throws Exception;

    /**
     * Get the {@link ResourceConsumerGateway} of the {@link JobMaster}. The future is only completed if
     * the JobMaster becomes leader.
     *
     * @return Future with the JobMasterGateway once the underlying JobMaster becomes leader
     */
    CompletableFuture<ResourceConsumerGateway> getResourceConsumerGateway();

    /**
     * Get the result future of this runner. The future is completed once the executed job reaches a
     * globally terminal state or if the initialization of the {@link JobMaster} fails. If the
     * result future is completed exceptionally via {@link ConsumeNotFinishedException}, then this
     * signals that the job has not been completed successfully. All other exceptional completions
     * denote an unexpected exception which leads to a process restart.
     *
     * @return Future which is completed with the job result
     */
    CompletableFuture<ResourceConsumerRunnerResult> getResultFuture();

    /**
     * Get the job id of the executed job.
     *
     * @return job id of the executed job
     */
    ConsumerID getConsumerID();

    /**
     * Cancels the currently executed job.
     *
     * @param timeout of this operation
     * @return Future acknowledge of the operation
     */
    CompletableFuture<Acknowledge> cancel(Time timeout);

    /**
     * Flag indicating if the JobManagerRunner has been initialized.
     *
     * @return true if the JobManagerRunner has been initialized.
     */
    boolean isInitialized();
}
